package acewem.utilities.test;

import gamlss.distributions.DistributionSettings;
import gamlss.utilities.oi.CSVFileReader;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.commons.math3.linear.ArrayRealVector;
import org.apache.commons.math3.linear.BlockRealMatrix;
import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression;

import acewem.market.ACEWEMmodel;

public class Regression extends OLSMultipleLinearRegression{
	
	private double[] dataIn;
	private double[] y;
	private double[][] X;

	public  Regression()
	{
		 
	}
	public double[] analyse(){
		
		 String fileName = "c:\\test.csv";	
		 CSVFileReader readData = new CSVFileReader(fileName);
		 readData.readFile();
		 ArrayList<String> data = readData.storeValues;
		 
		 dataIn = new double[3*data.size()];
		 y = new double[data.size()];
		 X = new double[data.size()][2];
		 int k =0;

		 for(int i=0;i<data.size();i++)
		 {
			String[] line = data.get(i).split(",");
			//y[i] = Double.parseDouble(line[0]);	
			//X[i][0] =  Double.parseDouble(line[1]);
			//X[i][1] =  Double.parseDouble(line[2]);
			
			dataIn[k+i] = Double.parseDouble(line[0]);
			dataIn[k+i+1] = Double.parseDouble(line[1]);
			dataIn[k+i+2] = Double.parseDouble(line[2]);
			k=k+2;
		 }	
		 
	    	OLSMultipleLinearRegression ols = new OLSMultipleLinearRegression();
	    	//ols.newSampleData(y, X);
	    	ols.newSampleData(dataIn, dataIn.length/3, 2);
		    return ols.estimateRegressionParameters();
		    
//double result = coeff[0]+ coeff[1]*14.02322848+coeff[2]*80.65863414*80.65863414; // 1
	
		    
//System.out.println(result+"  "+coeff[0]+" "+coeff[1]+" "+coeff[2]);
	}
   
	
	
	public static void main(String[] args){
        
    	Regression rgs = new  Regression();

	
  	}
	
	//1.7827518609782942E-14 0.9999999999999993 -1.3801958287711027E-17
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}

